package com.web.document.controller;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import com.web.common.document.api.DocumentShareApi;
import com.web.common.document.entity.DocumentContent;
import com.web.common.document.entity.ShareDocInfo;
import com.web.common.result.R;
import com.web.document.service.impl.ShareDocInfoServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "文档信息")
@Controller
@RequestMapping("/doc/share")
public class DocumentShareController implements DocumentShareApi {
	
	@Autowired
	private ShareDocInfoServiceImpl shareDocInfoServiceImpl;

	@Operation(summary = "获取文档信息列表")
	@Override
	public R<ShareDocInfo> shareDocToAllUser(String shareCode) {
		return shareDocInfoServiceImpl.shareDocInfo(shareCode);
	}

	@Operation(summary = "获取文档章节内容")
	@Override
	public R<DocumentContent> shareDocContent(String shareCode, String index) {
		return shareDocInfoServiceImpl.shareDocContent(shareCode, index);
	}

	@Operation(summary = "模糊查询文档内容")
	@Override
	public R<List<DocumentContent>> searchDocContent(String shareCode, String content) {
		if(!StringUtils.hasText(content)) {
			return R.ok(new ArrayList<>());
		}
		return shareDocInfoServiceImpl.searchDocContent(shareCode, content);
	}
}
